@extends('admin.main')
@section('body')
    <div class="main-title">
        <h2>水桶品牌管理</h2>
    </div>

    <!-- 表格列表 -->
    <div class="tb-unit posr">
        <div class="cf">
            <div class="fl">
                <a class="btn" href="{{urlPlat('single','getBucketCategoryAdd')}}">新 增</a>
            </div>
        </div>
        <div class="category">
            <div class="hd cf">
                <div class="order">序号</div>
                <div class="name">名称</div>
                <div class="status">状态</div>
                <div class="created_time">创建时间</div>
                <div class="operate">操作</div>
            </div>
            @if(count($tree))
                @foreach($tree as $k=>$v)
                    <dl class="cate-item">
                        <dt class="cf">
                            <div class="order">
                                {{$k+1}}
                            </div>
                            <div class="name">
                                {{$v['title']}}
                            </div>
                            <div class="status">
                                @if($v['status'] == 1)
                                    <span style="color: blue;">已启用</span>
                                @else
                                    <span style="color: red;">已禁用</span>
                                @endif
                            </div>
                            <div class="created_time">
                                {{$v['created_at']}}
                            </div>
                            <div class="operate">
                                @if($v['status'] == 1)
                                    <a href="{{urlPlat('single','anyChangeBucketCategoryStatus',['status'=>0,'ids'=>$v['id']])}}"
                                       class="ajax-get">禁用</a>
                                @else
                                    <a href="{{urlPlat('single','anyChangeBucketCategoryStatus',['status'=>1,'ids'=>$v['id']])}}"
                                       class="ajax-get">启用</a>
                                @endif
                            </div>
                        </dt>
                    </dl>
                @endforeach
            @else
                <div align="center">
                    <span style="text-align: center;font-size:15px;">aOh! 暂时还没有内容!</span>
                </div>
            @endif
        </div>
    </div>
    <!-- /表格列表 -->
@endsection
@section('script')
    <script type="text/javascript">
        (function ($) {
            /* 分类展开收起 */
            $(".category dd").prev().find(".fold i").addClass("icon-unfold")
                    .click(function () {
                        var self = $(this);
                        if (self.hasClass("icon-unfold")) {
                            self.closest("dt").next().slideUp("fast", function () {
                                self.removeClass("icon-unfold").addClass("icon-fold");
                            });
                        } else {
                            self.closest("dt").next().slideDown("fast", function () {
                                self.removeClass("icon-fold").addClass("icon-unfold");
                            });
                        }
                    });

            /* 三级分类删除新增按钮 */
            $(".category dd dd .add-sub").remove();

            /* 实时更新分类信息 */
            $(".category")
                    .on("submit", "form", function () {
                        var self = $(this);
                        $.post(
                                self.attr("action"),
                                self.serialize(),
                                function (data) {
                                    /* 提示信息 */
                                    var name = data.status ? "success" : "error", msg;
                                    msg = self.find(".msg").addClass(name).text(data.info)
                                            .css("display", "inline-block");
                                    setTimeout(function () {
                                        msg.fadeOut(function () {
                                            msg.text("").removeClass(name);
                                        });
                                    }, 1000);
                                },
                                "json"
                        );
                        return false;
                    })
                    .on("focus", "input", function () {
                        $(this).data('param', $(this).closest("form").serialize());

                    })
                    .on("blur", "input", function () {
                        if ($(this).data('param') != $(this).closest("form").serialize()) {
                            $(this).closest("form").submit();
                        }
                    });
        })(jQuery);

        /* 状态搜索子菜单 */
        $(".search-form").find(".drop-down").hover(function(){
            $("#sub-sch-menu").removeClass("hidden");
        },function(){
            $("#sub-sch-menu").addClass("hidden");
        });
        $("#sub-sch-menu li").find("a").each(function(){
            $(this).click(function(){
                var text = $(this).text();
                $("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
                $("#sub-sch-menu").addClass("hidden");
                var shop_id = $(this).attr("value");
                window.location.href = '{{urlPlat('single','getBucketCategory')}}?shop_id='+shop_id;
            })
        });
    </script>
@endsection
